package com.ytxg.resource.service.impl;

import com.ytxg.core.dto.RestResp;
import com.ytxg.core.utils.ImgVerifyCodeUtils;
import com.ytxg.resource.dto.ImgVerifyCodeRespDto;
import com.ytxg.resource.service.ResourceService;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class ResourceServiceImpl implements ResourceService {
    @Override
    public RestResp<ImgVerifyCodeRespDto> getImgVerifyCode() {
        String randomVerifyCode = ImgVerifyCodeUtils.getRandomVerifyCode(4);

        try {
            String s = ImgVerifyCodeUtils.genVerifyCodeImg(randomVerifyCode);
            ImgVerifyCodeRespDto build = ImgVerifyCodeRespDto.builder()
                    .img(s)
                    .sessionId(randomVerifyCode)
                    .build();
            return RestResp.ok(build);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
